<?php
namespace Api\Controller;
use Think\Controller;
class PetController extends Controller {
	//添加宠物
	public function AddOrEditPet(){
       $id           =I('id');
       $add['p_uid'] =I('uid');//用户id
       $data         =I('head');//头像
       $headimgname=time().rand(10000,99999);
       $dirurl='Public/api/imgs/head/'.$headimgname.'.jpg';
       moveFileToDir($data,$dirurl);
       $add['p_head']    =$dirurl;
       $add['p_name']    =I('name');//名字
       $add['p_sex']     =I('indexsex');//性别
       $add['p_birthday']=I('datebirthday');//生日
       $add['p_jue']     =I('indexjue');//是否绝育
       $add['p_class']   =I('indexpj');//品种
       $add['p_type']    =I('typeid');//品种类型
       $add['p_kqb']     =I('kqb');//狂犬病
       $add['p_crb']     =I('crb');//传染病
       $add['p_tnqc']    =I('tnqc');//体内驱虫
       $add['p_twqc']    =I('twqc');//体外驱虫
       if($id){
             $where['id']=$id;
             $Pid=se('Pet',$where,$add);
       }else{
             $Pid=ad('Pet',$add);
       }
       if($Pid){
       	EchoData($Pid,1,100,'操作成功',0);
       }else{
       	EchoData('',0,'101','操作失败',0);
       }
   }
   //获取宠物列表
   public function ToUidGetPetListInfo(){
   	$where['p_uid']=I('uid');
   	$info=st('Pet',$where,'id,p_head,p_name,p_birthday','id desc');
   	foreach ($info as $key => $value) {
   		$info[$key]['p_head'] =C('HOST_URL').$value['p_head'];
   	}
   	if($info){
   		EchoData($info);
   	}else{
   		EchoData('',0,101,'失败',0);
   	}
   }
   //通过宠物id获取宠物信息
   public function ToPidGetPetInfo(){
   	$where['id']=I('id');
   	$info=fd('Pet',$where);
   	$info['p_kqb'] =explode(',',$info['p_kqb']);
   	$info['p_crb'] =explode(',',$info['p_crb']);
   	$info['p_tnqc']=explode(',',$info['p_tnqc']);
   	$info['p_twqc']=explode(',',$info['p_twqc']);
   	$info['p_head']=C('HOST_URL').$info['p_head'];
    $info['classtype']=D('PetClass')->GetPetTypeName($info['p_type']);
   	EchoData($info);
   }
   //获取猫咪and者狗狗的类型
   public function GetPetClassInfo(){
      $info=D('PetClass')->GetPetClass();
      EchoData($info);
   }
}